﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Acms.Bll;
using Acms.DataControls;

public partial class Templates_ContactPress_Default : Acms.AcmsControls.TemplatePage
{

    protected override void OnInit(EventArgs e)
    {
        base.OnInit(e);
        dsSibling.SelectData += new EventHandler<Acms.DataControls.SelectEventArgs<Acms.Bll.Post>>(dsSibling_SelectData);
        dlNavSiblings.ItemDataBound += new EventHandler<Acms.WebControls.ItemDataBoundEventArgs>(dlNavSiblings_ItemDataBound);
    }
    protected void Page_Load(object sender, EventArgs e)
    {
        btnSubmit.Click += new EventHandler(btnSubmit_Click);
        if (!IsPostBack)
        {
            
        }

    }
    void dsSibling_SelectData(object sender, Acms.DataControls.SelectEventArgs<Acms.Bll.Post> e)
    {
        e.SetData(AcmsContext.CurrentPost.Parent.Children.OrderBy(x => x.Sequence).ToList());
    }
    void dlNavSiblings_ItemDataBound(object sender, Acms.WebControls.ItemDataBoundEventArgs e)
    {
        var post = e.DataItem as Post;
        if (post != null)
        {
            var lnk = e.Item.FindControl("lnkNav") as HyperLink;

            if (lnk != null)
            {
                lnk.Text = post.DisplayName;
                lnk.NavigateUrl = post.Url;
            }
        }
    }



    void btnSubmit_Click(object sender, EventArgs e)
    {
        Validate();
        if (IsValid)
        {
            //create the mail message
            System.Net.Mail.MailMessage mail = new System.Net.Mail.MailMessage();

            //set the addresses
            mail.To.Add(new System.Net.Mail.MailAddress("pr@schiebel.net", "Schiebel"));
            //mail.To.Add(new System.Net.Mail.MailAddress("t.armfelt@gmail.com", "PureStretch"));
            mail.Bcc.Add("acmsemail@gmail.com");
            //mail.To.Add(new System.Net.Mail.MailAddress("toma57@hotmail.com", "Moo Me"));

            mail.From = new System.Net.Mail.MailAddress(txtEmail.Text, txtName.Text);
            //mail.To.Add("you@yourcompany.com");

            //set the content
            mail.Subject = "Email Schiebel.net Press Contact";
            mail.Body = string.Concat(
                "From: ", txtName.Text+" "+ txtLastName.Text,
                "\n Publication: ", txtPublication.Text,
                "\n Address1: ", txtAddress1.Text,
                "\n Address2: ", txtAddress2.Text,
                "\n Country: ", txtCountry.Text,
                "\n StateCode: ", txtStateCode.Text,
                "\n Email: ", txtEmail.Text,
                "\n Telephone: ", txtTelephone.Text,
                "\n Fax: ", txtFax.Text,
                "\n ListProduct: ", chkListProduct.Text,
                "\n Description: ", txtDescription.Text
                );
            /*if (tx.Text != "")
            {
                //var phone = string.Concat("Phone Number:", txtPhone.Text, "--");
                mail.Body = string.Concat("Phone Number: ", txtPhone.Text, " -- ", txtQuestion.Text);
            }
            else
            {
                mail.Body = string.Concat("No Phone Number Provided. ", txtQuestion.Text);
            }*/

            try
            {
                System.Net.Mail.SmtpClient client = new System.Net.Mail.SmtpClient();
                client.Send(mail);
                mail.Dispose();
                pnlMessageSent.Visible = true;
                pnlCreateMsg.Visible = false;
            }
            catch
            {
                pnlCreateMsg.Visible = false;
                pnlMessageError.Visible = true;

            }
        }
    }

}
